import { A, RouteDefinition } from "@solidjs/router";
import { ILoginRequest, LoginRequest, V1Client } from "@src/services/v1_client";
import { useClient } from "@src/utils/useHelper";
import { TextBox, FcForm, FcFormItem, FcFormSubmit } from "solid-fire-controls";
import { Component, createSignal } from "solid-js";

const client = useClient(V1Client);

const Login: Component = () => {
  const handleSubmit = (formValue: ILoginRequest) => {
    return client
      .postApiIdentityV1Login(null, null, new LoginRequest(formValue))
      .then((resp) => {})
      .catch((err) => {});
  };

  return (
    <div class="row justify-content-center align-items-center w-100 h-100">
      <div class="col-12 col-sm-4">
        <h1>登录</h1>
        <div class="card">
          <div class="card-body">
            <FcForm onSubmit={handleSubmit}>
              <FcFormItem label="Email">
                <TextBox classList={{ "mb-3": true }}></TextBox>
              </FcFormItem>
              <FcFormItem label="密码">
                <TextBox
                  type="password"
                  clearable={false}
                  classList={{ "mb-3": true }}
                ></TextBox>
              </FcFormItem>
              <div class="w-100 ps-1 pe-1 mb-3 d-flex justify-content-between">
                <A href="/forgot-password">忘记密码?</A>
                <A class="float-right" href="/register">
                  注册
                </A>
              </div>
              <FcFormSubmit
              >
                登录
              </FcFormSubmit>
            </FcForm>
          </div>
        </div>
      </div>
    </div>
  );
};

export const LoginRoute: RouteDefinition = {
  path: "/login",
  component: Login,
};

export default Login;
